//
//  Combined.m
//  DayDayRun
//
//  Created by 卫建 on 16/1/20.
//  Copyright © 2016年 卫建. All rights reserved.
//

#import "Combined.h"
#import <CoreLocation/CoreLocation.h>
@implementation Combined

//计算距离    原来距离  (单位M)   采集地点得数组格式  { str1, str2,str3 }  // str1=  "123456.432, 76541.432"
//返回值也是M
+(NSInteger)calculateTotalDistance:(NSInteger)currentDistance LocationData:(NSArray *)locationData;
{
    if ([locationData count]<2)
    {//数组内地点少于两个  返回原来距离
        return currentDistance;
    }
    else
    {
        NSString *oldLocation=[locationData objectAtIndex:[locationData count]-2];//上次地点
        NSString *newLocation=[locationData objectAtIndex:[locationData count]-1];//当前地点
        NSArray *oldArray=[oldLocation componentsSeparatedByString:@","];
        NSArray *newArray=[newLocation componentsSeparatedByString:@","];
        
        if ([oldArray count]==2 && [newArray count]==2 ) {
            CLLocation *oldLocations=[[CLLocation alloc] initWithLatitude:[[oldArray objectAtIndex:0] doubleValue]  longitude:[[oldArray objectAtIndex:1] doubleValue]];
            CLLocation *newLocations=[[CLLocation alloc] initWithLatitude:[[newArray objectAtIndex:0] doubleValue]  longitude:[[newArray objectAtIndex:1] doubleValue]];
            CLLocationDistance meters=[oldLocations distanceFromLocation:newLocations];
            NSInteger backMeter=currentDistance + meters;
            return backMeter;
        }
    }
    return nil;
}


@end
